﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MX.Core.Http.WebAction
{
    /// <summary>
    /// 表单的ContentType
    /// </summary>
    public class PostContentType
    {
        public const string text_plain = "text/plain; charset={0}";
        public const string multipart_form_data = "multipart/form-data; boundary={0}";
        public const string application_x_www_form_urlencoded = "application/x-www-form-urlencoded; charset={0}";
        public const string application_json = "application/json; charset={0}";
        string _contentType = "";
        string _prefix = "";
        public string Prefix { get { return _prefix; } }
        public string ContentType { get { return _contentType; } }
        protected PostContentType(string contentType,string prefix)
        {
            _prefix = prefix;
            _contentType = contentType;
        }
        static public PostContentType MultipartFormdata(string boundary)
        {
            return new PostContentType(string.Format(multipart_form_data, boundary), boundary);
        }
        static public PostContentType Application_XWwwFormUrlencoded(string charset = "UTF-8")
        {
            return new PostContentType(string.Format(application_x_www_form_urlencoded, charset), charset);
        }
        static public PostContentType Text_Plain(string charset = "UTF-8")
        {
            return new PostContentType(string.Format(text_plain, charset), charset);
        }
        static public PostContentType GetContentType(string contentType)
        {
            return new PostContentType(contentType,"");
        }
        static public PostContentType Application_Json(string charset = "UTF-8")
        {

            return new PostContentType(String.Format(application_json, charset.ToUpper()), charset);

        }

    }
}
